﻿using DadayunApi.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace KhtApi.Model
{
    public class BomPeggingReport
    {
        public List<BomPeggingReportResult> Results { get; set; }
        /// <summary>
        /// 将报表查询结果转换成BOM反查清单
        /// </summary>
        /// <returns></returns>
        public List<BomPegging> ToBomPeggings()
        {
            List<BomPegging> list = null;
            if(Results.Count>0)
            {
                list = new List<BomPegging>();
                foreach (var r in Results)
                {
                    list.Add(r.ToBomPegging());
                }
            }           
            return list;
        }
    }

    public class BomPeggingReportResult
    {
        public int RowNum { get; set; }

        [JsonProperty(PropertyName = "物料编码", NullValueHandling = NullValueHandling.Ignore)]
        public string MatCode { get; set; }
        [JsonProperty(PropertyName = "物料名称", NullValueHandling = NullValueHandling.Ignore)]
        public string MatName { get; set; }
        [JsonProperty(PropertyName = "物料型号", NullValueHandling = NullValueHandling.Ignore)]
        public string MatModelNo { get; set; }
        [JsonProperty(PropertyName = "物料规格", NullValueHandling = NullValueHandling.Ignore)]
        public string MatSpec { get; set; }
        [JsonProperty(PropertyName = "BOM单号", NullValueHandling = NullValueHandling.Ignore)]
        public string BomId { get; set; }
        [JsonProperty(PropertyName = "是否已审核", NullValueHandling = NullValueHandling.Ignore)]
        public string IsVerified { get; set; }
        [JsonProperty(PropertyName = "生效状态", NullValueHandling = NullValueHandling.Ignore)]
        public string IsUsing { get; set; }
        [JsonProperty(PropertyName = "版本号", NullValueHandling = NullValueHandling.Ignore)]
        public double Version { get; set; }
        [JsonProperty(PropertyName = "生效日期", NullValueHandling = NullValueHandling.Ignore)]
        /// <summary>
        /// 生效日期
        /// </summary>
        /// 
        public DateTime EffDate { get; set; }
        [JsonProperty(PropertyName = "失效日期", NullValueHandling = NullValueHandling.Ignore)]
        /// <summary>
        /// 失效时间
        /// </summary>
        public DateTime DisableDate { get; set; }
        [JsonProperty(PropertyName = "产品编码", NullValueHandling = NullValueHandling.Ignore)]
        public string PrdCode { get; set; }
        [JsonProperty(PropertyName = "产品名称", NullValueHandling = NullValueHandling.Ignore)]
        public string PrdName { get; set; }
        [JsonProperty(PropertyName = "产品型号", NullValueHandling = NullValueHandling.Ignore)]
        public string PrdModelNo { get; set; }
        [JsonProperty(PropertyName = "产品规格", NullValueHandling = NullValueHandling.Ignore)]
        public string PrdSpec { get; set; }
        [JsonProperty(PropertyName = "产品来源", NullValueHandling = NullValueHandling.Ignore)]
        public string PrdOrigin { get; set; }
        
        public ReportDataObject DataObjs { get; set; }

        public BomPegging ToBomPegging()
        {
            BomPegging bom = new BomPegging
            {
                BomId = BomId,
                DisableDate = DisableDate,
                EffDate = EffDate,
                InstanceId = DataObjs.FormInstances[0].InstanceId,
                IsUsing = this.IsUsing == "生效" ,
                IsVerified = this.IsVerified == "是" ,
                MatCode = MatCode,
                MatModelNo = MatModelNo,
                MatName = MatName,
                MatSpec = MatSpec,
                PrdName=PrdName,
                PrdCode = PrdCode,
                PrdModelNo = PrdModelNo,
                PrdOrigin = PrdOrigin,
                PrdSpec = PrdSpec,
                Version = Version
            };
            return bom;
        }
    }

    
}
